package com.ywl.utils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 进行字符串处理
 *
 * @author 24040
 * @name MyStringUtils
 * @date 2022-08-29 11:37
 */
public class MyStringUtils {

    public static String getFirstImg(String imgs,String ch){
        String[] imgUrl = stringToArray(imgs, ",");
        String img = imgUrl[0];
        return img;
    }

    public static List<String> stringToList(String imgs,String ch){
        String[] imgUrl = stringToArray(imgs, ",");
        List<String> imgUrlList = Arrays.stream(imgUrl)
                .parallel()
                .collect(Collectors.toList());
        return imgUrlList;
    }

    /**
     * 将图片字符串转换成数组
     * @param imgs 图片字符串
     * @param ch  分隔字符
     * @return 字符串数组，以，号分隔
     */
    public static String[] stringToArray(String imgs,String ch){
        int first = imgs.indexOf('[');
        int last = imgs.indexOf(']');
        String temp = imgs.substring(first + 1, last);
        String[] imgUrl = temp.split(",");
        return imgUrl;
    }
}
